package com.cat.greedyAlgorithm;

import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-element-sum-of-a-complete-subset-of-indices/
 * @create 2025/10/12 20:46
 * @since JDK17
 */

public class Solution89 {
    public long maximumSum(List<Integer> nums) {
        int n = nums.size();
        long[] sum = new long[n + 1];
        long ans = 0;
        for (int i = 0; i < n; i++) {   //
            int num = core(i + 1);
            sum[num] += nums.get(i);
            ans = Math.max(ans, sum[num]);
        }

        return ans;
    }
    int core(int n) {
        for (int i = 2; i * i <= n; i++) {
            while (n % (i * i) == 0) {
                n /= i * i;
            }
        }
        return n;
    }
}
